package com.shexianyu.difficult;

import com.shexianyu.test.Solution;

import java.util.HashMap;

public class IsRectangleCover {
    public static void main(String[] args) {
        //int[][] rectangles = {{1, 1, 2, 3}, {1, 3, 2, 4}, {3, 1, 4, 2}, {3, 2, 4, 4}};
        //int[][] rectangles = {{0, 0, 1, 1}, {0, 1, 3, 2}, {1, 0, 2, 2}};
        //0,0
        //1,1    4,4==>(1,4)(4,1)
        //int[][] rectangles = {{1, 1, 3, 3}, {3, 1, 4, 2}, {1, 3, 2, 4}, {2, 2, 4, 4}};
        int[][] rectangles = {{1, 1, 3, 3}, {3, 1, 4, 2}, {3, 2, 4, 4}, {1, 3, 2, 4}, {2, 3, 3, 4}};
        Solution solution = new Solution();
        System.out.println(solution.isRectangleCover(rectangles));
        //System.out.println(isRectangleCover(rectangles));
    }

    public static boolean isRectangleCover(int[][] rectangles) {
        int row = rectangles.length;
        int area = 0;
        for (int i = 0; i < row; i++) {
            area += (rectangles[i][2] - rectangles[i][0]) * (rectangles[i][3] - rectangles[i][1]);
        }
        int x1 = rectangles[0][0];
        int x2 = rectangles[0][1];
        int a1 = rectangles[0][2];
        int a2 = rectangles[0][3];
        for (int i = 0; i < row; i++) {
            x1 = Math.min(x1, rectangles[i][0]);
            x2 = Math.min(x2, rectangles[i][1]);
            a1 = Math.max(a1, rectangles[i][2]);
            a2 = Math.max(a2, rectangles[i][3]);
        }
        System.out.println("x1=" + x1);
        System.out.println("x2=" + x2);
        System.out.println("a1=" + a1);
        System.out.println("a2=" + a2);
       /* for (int i = 0; i < row; i++) {
            if ((rectangles[0][i] == x1) && (rectangles[i][0] == a2) && (rectangles[i][0] == x1) && (rectangles[i][0] == a2))
        }*/
        //x1,a2 a1,x2

        int totalArea = (a1 - x1) * (a2 - x2);
        System.out.println(totalArea);
        System.out.println(area);
        if (area == totalArea) {
            return true;
        }
        return false;
    }

}
